<template>
  <div>
    <scroller :show-scrollbar="false">
      <vm-cell label="险种"
               :title="clz.ins_class_name"></vm-cell>

      <vm-cell label="产业名"
               :title="clz.ind_name"></vm-cell>

      <vm-cell label="产业类型"
               :title="clz.ind_category_name"></vm-cell>

      <vm-cell label="保险机构"
               :title="clz.agency_name"></vm-cell>

      <vm-cell label="险种年份"
               :title="clz.ins_year"></vm-cell>

      <vm-cell label="区域"
               :title="clz.address_code_name"></vm-cell>

      <vm-cell label="单位保额"
               :title="clz.ins_amount"></vm-cell>

      <vm-cell label="保费费率"
               :title="clz.ins_fee"></vm-cell>

      <vm-cell label="自缴比例"
               :title="`${clz.self_fee_rate}%`"></vm-cell>

      <vm-cell label="保险责任"
               :title="clz.ins_res"></vm-cell>

      <vm-cell label="中央补贴"
               :title="`${clz.center_fee_rate}%`"></vm-cell>

      <vm-cell label="省级补贴"
               :title="`${clz.pro_fee_rate}%`"></vm-cell>

      <vm-cell label="县级补贴"
               :title="`${clz.county_fee_rate}%`"></vm-cell>

      <vm-cell label="地市补贴"
               :title="`${clz.city_fee_rate}%`"></vm-cell>

      <vm-cell label="其它补贴"
               :title="`${clz.other_fee_rate}%`"></vm-cell>
    </scroller>

  </div>
</template>
<script>
import VmButton from '../../components/vm-button.vue'
import VmCell from '../../components/vm-cell.vue'
import {
  STORAGE_FARM
} from '../../plugins/constant'

export default {
  components: { VmButton, VmCell },
  props: {},
  data() {
    return {
      clz: {}
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getFarmInfo()
  },
  methods: {
    getFarmInfo() {
      this.farm = this.$storage.getSync(STORAGE_FARM) || {}
      this.getParams()

      this.$navigator.setRightItem({
        text: '申请'
      }, this.goApply)
    },
    getParams() {
      this.$router.getParams().then(res => {
        this.clz = res
      })
    },
    goApply() {
      if (+this.clz.ins_year < new Date().getFullYear()) {
        return this.$notice.toast({ message: '险种年份已过，不能再申请' })
      }
      this.checkApply().then(() => {
        this.$nav.open({
          name: 'serve.insurance.apply',
          params: { agency: this.clz }
        })
      }).catch(err => {
        this.$notice.toast({ message: (err && err.gmMessage) || '险种正在申请中' })
      })
    },
    checkApply() {
      // 判断是否在申请中，在申请中不能再申请
      return new Promise((resolve, reject) => {
        this.$api.getData({
          server: 'credit',
          table: 'datum_customer_insurance_order',
          params: {
            'customer_id.eq': this.farm.id,
            'insurance_order_no.eq': '',
            'insurance_class_id.eq': this.clz.insurance_class_id
          },
          empty: false
        }).then(res => {
          if (res && res.length) {
            reject({})
          } else {
            resolve()
          }
        }).catch(err => {
          reject(err)
        })
      })
    }
  }
}
</script>
<style lang="scss" scoped>
@import "../../css/variables.scss";
</style>
